clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

*****************************************************************************************************
********************************** Figure S3: Nonlinear effects of temperature on income per capita
*****************************************************************************************************

    // --- Mean income ---
    use "${date}/_data/spid_for_analysis_v2.dta", clear
	
	sort code year
		
	local temp_bin bin3_1 bin3_2 bin3_3 bin3_4 bin3_5 bin3_6 bin3_7  bin3_9 bin3_10 bin3_11 bin3_12 bin3_13
	local controls ln_GDPppp Unempilo agri manuf popgr 
	
    reghdfe mean2017 `temp_bin' rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	

	forval i=1(1)13 {
	cap gen estimate`i' = _b[bin3_`i']
	cap gen lb`i' = _b[bin3_`i'] - invttail(e(df_r),0.025)*_se[bin3_`i']
	cap gen ub`i' = _b[bin3_`i'] + invttail(e(df_r),0.025)*_se[bin3_`i']
	}

	gen estimate8=0
	gen lb8=0
	gen ub8=0

    gen n = _n
    keep if n == 1
    reshape long estimate lb ub, i(n) j(index)
    keep estimate lb ub index
    gen poor = 1

    graph twoway ///
        (rcap lb ub index if poor == 1, pstyle(ci) lcolor(navy%80) msize(medium) lwidth(medium)) ///
        (scatter estimate index if poor == 1, mcolor(navy%80)) ///	
        , scheme(white_tableau) ///
        xtitle("Temperature bin") ///
        xlabel(1 "<0" 2 "[0,3)" 3 "[3,6)" 4 "[6,9)" ///
	5 "[9,12)" 6 "[12,15)" 7 "[15,18)" 8 "[18,21)" 9 "[21,24)" 10 "[24,27)" 11 "[27,30)" ///
	12 "[30,33)" 13 "33+", nogrid) ///
        ylabel(, nogrid) ///
        ytitle("Effects of temperature")  ///
        yline(0, lcolor(black) lpattern(solid) lwidth(thin)) ///
        legend(off) name("gr1", replace)

    graph export "${date}/_figures/_fig_s3.pdf", as(pdf) replace	
	